package com.bang.concurrency.example.aqs;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * @ClassName: FutureExample
 * @Desc:
 * @auther: BANG
 * @Date: 2019/10/09 09:16
 * @Version: 1.0
 * @Modified By:
 */
@Slf4j
public class FutureTaskExample {


    public static void main(String[] args) throws Exception {
        ExecutorService executorService = Executors.newCachedThreadPool();
        FutureTask<String> futureTask = new FutureTask<>(new Callable<String>() {
            @Override
            public String call() throws Exception {
                Thread.sleep(5000);
                log.error("The MyCallable is running");
                return "down";
            }
        });
        executorService.submit(futureTask);
        executorService.submit(futureTask);
        log.error("Main线程开始执行-----------");
        String res = futureTask.get();
        log.error("res = {}", res);
        log.error("Main线程开始执行-----------");
        executorService.shutdown();

    }
}
